package reflect;

import java.lang.reflect.Constructor;

/**
 * 使用指定的构造器实例化对象
 */
public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");

        Constructor constructor = cls.getConstructor();
        Object obj = constructor.newInstance();
        System.out.println(obj);

        Constructor constructor1 = cls.getConstructor(String.class);
        Object obj1 = constructor1.newInstance("张三");
        System.out.println(obj1);

        Constructor constructor2 = cls.getConstructor(String.class,int.class);
        Object obj2 = constructor2.newInstance("李四",30);
        System.out.println(obj2);

    }
}
